/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.worsik.utils;

import java.util.ArrayList;
import java.util.List;
import javax.swing.SpinnerListModel;

/**
 *
 * @author 231260
 */
public class CyclicSpinnerListModel extends SpinnerListModel {

	public CyclicSpinnerListModel() {
		super();
	}

	public CyclicSpinnerListModel(List<?> list) {
		super(list);
	}

	public CyclicSpinnerListModel(Object[] os) {
		super(os);
	}
	
	@Override
	public Object getNextValue()
	{
		List<Object> list = new ArrayList(this.getList());
		// pokud jsme na maximu, vratime prvni hodnotu
		if (this.getValue() == list.get(list.size()-1))
			return list.get(0);
		else
			return list.get(list.indexOf(this.getValue())+1);
	}
	
	@Override
	public Object getPreviousValue()
	{
		List<Object> list = new ArrayList(this.getList());
		// pokud jsme na minimu, vratime posledni hodnotu
		if (this.getValue() == list.get(0))
			return list.get(list.size()-1);
		else
			return list.get(list.indexOf(this.getValue())-1);
	}
}
